package cn.xinfei.xdecision.data.core.frame.executors.collect.filter;

import cn.xinfei.xdecision.common.model.datax.datamanage.v2.Variable;
import cn.xinfei.xdecision.common.model.datax.enums.VariableEnum;
import org.apache.commons.collections4.CollectionUtils;

import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;


public class ConstVarFilter implements VarFilter<Variable> {

    @Override
    public Set<Variable> actionVar(Set<Variable> variables) {
        if (CollectionUtils.isEmpty(variables)) {
            return Collections.emptySet();
        }
        return Optional.of(variables).orElse(Collections.emptySet())
                .stream()
                .filter(var -> var.getVarValueType().equals(Integer.valueOf(VariableEnum.CONSTANT_VAR.getCode())))
                .collect(Collectors.toSet());
    }
}
